/*
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2020-10-20 17:48:29
 * @LastEditors: sueRimn
 * @LastEditTime: 2020-11-18 14:42:14
 */
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import SecondLayout from '@/SecondLayout/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }

 console.log('====================================')
 console.log('关闭Tag', this.$route)
 console.log('====================================')
 this.$store.dispatch('tagsView/delView', this.$route)
 this.$router.replace('/organizingPapers/index')
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  //   {
  //     path: '/login',
  //     component: () => import('@/views/login/index'),
  //     hidden: true
  //   },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'home',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'el-icon-s-home', noCache: true, affix: true }
    }]
  },
  {
    path: '/recruit',
    component: Layout,
    redirect: '/recruit',
    alwaysShow: true,
    meta: { title: '学员管理', icon: 'el-icon-user', roles: ['*'] },
    children: [{
      path: 'recruit',
      name: 'recruit',
      component: () => import('@/views/recruit/index'),
      meta: { title: '学员列表', icon: 'el-icon-user', noCache: true, affix: true }
    }/*, {
      path: 'city',
      name: 'city',
      component: () => import('@/views/recruit/components/city'),
      meta: { title: '城市级联', icon: 'el-icon-s-home', noCache: true, affix: true }
    }, {
      path: 'home',
      name: 'home',
      component: () => import('@/views/home/index'),
      meta: { title: '智测用户', icon: 'el-icon-s-home', noCache: true, affix: true }
    }*/]
  },
  {
    path: '/student',
    component: Layout,
    redirect: '/student',
    alwaysShow: true,
    meta: { title: '学员管理(新)', icon: 'el-icon-user', roles: ['*'] },
    children: [{
      path: 'student',
      name: 'student',
      component: () => import('@/views/student/index'),
      meta: { title: '学员列表(新)', icon: 'el-icon-user', noCache: true, affix: true }
    }]
  },
  {
    path: '/teachingMaterial',
    component: Layout,
    redirect: '/teachingMaterial',
    alwaysShow: true,
    meta: { title: '教材管理', icon: 'el-icon-reading', roles: ['*'] },
    children: [{
      path: 'teachingMaterial',
      name: 'teachingMaterial',
      component: () => import('@/views/teachingMaterial/index'),
      meta: { title: '教材列表', icon: 'el-icon-reading', noCache: true, affix: true }
    }]
  },
  {
    path: '/charge',
    component: Layout,
    redirect: '/charge',
    alwaysShow: true,
    meta: { title: '收费管理', icon: 'el-icon-coin', roles: ['*'] },
    children: [{
      path: 'charge',
      name: 'charge',
      component: () => import('@/views/charge/index'),
      meta: { title: '收费课程', icon: 'el-icon-coin', noCache: true, affix: true }
    },{
      path: 'charge2',
      name: 'charge2',
      component: () => import('@/views/charge/index2'),
      meta: { title: '其他收费项', icon: 'el-icon-coin', noCache: true, affix: true }
    }]
  },
  {
    path: '/dictionaries',
    component: Layout,
    redirect: '/dictionaries',
    alwaysShow: true,
    meta: { title: '数据字典', icon: 'el-icon-collection', roles: ['*'] },
    children: [{
      path: 'dictionaries',
      name: 'dictionaries',
      component: () => import('@/views/dictionaries/index'),
      meta: { title: '教材列表', icon: 'el-icon-collection', noCache: true, affix: true }
    }]
  },
  {
    path: '/semester',
    component: Layout,
    redirect: '/semester',
    alwaysShow: true,
    meta: { title: '学期管理', icon: 'el-icon-collection', roles: ['*'] },
    children: [{
      path: 'semester',
      name: 'semester',
      component: () => import('@/views/semester/index'),
      meta: { title: '上课时间设置', icon: 'el-icon-collection', noCache: true, affix: true }
    },{
      path: 'semester2',
      name: 'semester2',
      component: () => import('@/views/semester/index2'),
      meta: { title: '学期设置', icon: 'el-icon-coin', noCache: true, affix: true }
    }]
  },
  {
    path: '/number',
    component: Layout,
    redirect: '/number',
    children: [{
      path: 'number',
      name: 'number',
      component: () => import('@/views/number/index'),
      meta: { title: '市场部门', icon: 'el-icon-s-home', noCache: true, affix: true }
    }]
  },
]

export const asyncRoutes = [
  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/institutionsList',
    alwaysShow: true,
    meta: { title: 'Admin管理者', icon: 'el-icon-s-grid', roles: ['*'] },
    children: [{
      path: 'institutionsList',
      name: 'InstitutionsList',
      component: () => import('@/views/admin/staffList/index'),
      meta: { title: '机构列表', icon: 'el-icon-s-custom', noCache: false }
    }, {
      path: 'pageAuth',
      name: 'PageAuth',
      component: () => import('@/views/admin/pageAuth/index'),
      meta: { title: '模块页面权限', icon: 'el-icon-s-tools', noCache: false }
    }]
  },
  {
    path: '/intelligentTest',
    component: Layout,
    redirect: '/intelligentTest/index',
    alwaysShow: true,
    meta: { title: '智测列表', icon: 'el-icon-tickets', roles: ['5fa50a4d4cf7c'] },
    children: [{
      path: 'index',
      name: 'IntelligentTest',
      component: () => import('@/views/intelligentTest/index'),
      meta: { title: '问卷/试题列表', icon: 'el-icon-s-marketing' }
    }, {
      path: 'recycleBin',
      name: 'IntelligentTestRecycleBin',
      hidden: true,
      component: () => import('@/views/intelligentTest/recycleBin/index'),
      meta: { title: '回收站', noCache: false }
    }, {
      path: 'projectAdd',
      name: 'ProjectAdd',
      hidden: true,
      component: () => import('@/views/intelligentTest/projectAdd/index'),
      meta: { title: '新增试题/问卷', noCache: false }
    }, {
      path: 'projectEdit',
      name: 'ProjectEdit',
      hidden: true,
      component: () => import('@/views/intelligentTest/projectEdit/index'),
      meta: { title: '编辑试题/问卷', noCache: false }
    }, {
      path: 'zoomProjectEdit',
      name: 'ZoomProjectEdit',
      hidden: true,
      component: () => import('@/views/intelligentTest/projectEdit/editzoom'),
      meta: { title: '编辑组卷', noCache: false }
    }, {
      path: 'zoomAdd',
      name: 'ZoomAdd',
      hidden: true,
      component: () => import('@/views/intelligentTest/projectAdd/addzoom'),
      meta: { title: '新增组卷', noCache: false }
    }, {
      path: 'organizingPapers',
      name: 'OrganizingPapers',
      component: () => import('@/views/organizingPapers'),
      meta: { title: '组卷列表', icon: 'el-icon-s-order', noCache: false }
    }, {
      path: 'organizingPapers/recycleBin',
      name: 'OrganizingPapersRecycleBin',
      hidden: true,
      component: () => import('@/views/organizingPapers/recycleBin/index'),
      meta: { title: '组卷回收站', noCache: false }
    }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/IntelligentTestUsers',
    meta: { roles: ['5fa50a4d4cf7c'] },
    children: [{
      path: 'IntelligentTestUsers',
      name: 'IntelligentTestUsers',
      component: () => import('@/views/IntelligentTestUsers/index'),
      meta: { title: '智测用户', icon: 'el-icon-s-custom', noCache: false }
    }, {
      path: 'previewReport',
      name: 'PreviewReport',
      hidden: true,
      component: () => import('@/views/IntelligentTestUsers/previewReport/index'),
      meta: { title: '报告预览', noCache: true }
    }]
  },

  {
    path: '/personnelManagement',
    component: Layout,
    redirect: '/staffList',
    meta: {
      title: '人事管理', icon: 'el-icon-s-check', roles: ['5fa50a6403755']
    },
    children: [{
      path: 'staffList',
      name: 'StaffList',
      component: () => import('@/views/personnelManagement/staffList/index'),
      meta: { title: '员工列表', icon: 'el-icon-s-custom', noCache: false }
    }, {
      path: 'PersonnelStructure',
      name: 'PersonnelStructure',
      component: () => import('@/views/personnelManagement/PersonnelStructure/index'),
      meta: { title: '人事构架', icon: 'el-icon-menu', noCache: false }
    }, {
      path: 'addStaff',
      name: 'AddStaff',
      hidden: true,
      component: () => import('@/views/personnelManagement/staffList/addStaff'),
      meta: { title: '新增员工', icon: 'el-icon-s-custom', noCache: false }
    },
      {
        path: 'editStaff',
        name: 'EditStaff',
        hidden: true,
        component: () => import('@/views/personnelManagement/staffList/editStaff'),
        meta: { title: '编辑员工', icon: 'el-icon-s-custom', noCache: false }
      }]
  },
  {
    path: '/trembleSchool',
    component: Layout,
    redirect: '/trembleSchool/index',
    alwaysShow: true,
    meta: { title: '抖校管理', icon: 'el-icon-video-camera-solid' },
    children: [{
      path: 'school',
      name: 'TrembleSchool', // 由于是嵌套路由，它会忽略之前定义的规则，页面有多个route-view,需要多级缓存，导致第一级Name无法缓存，将children的name设置为相同即可
      meta: { title: '校园展示', icon: 'el-icon-school', noCache: false },
      alwaysShow: true,
      component: SecondLayout,
      children: [{
        path: 'introduce',
        name: 'Introduce',
        component: () => import('@/views/trembleSchool/introduce/index'),
        meta: { title: '校园介绍', noCache: false }
      }]
    }, {
      path: 'contentManagement',
      name: 'TrembleSchool', // 由于是嵌套路由，它会忽略之前定义的规则，页面有多个route-view,需要多级缓存，导致第一级Name无法缓存，将children的name设置为相同即可
      meta: { title: '内容管理', icon: 'el-icon-s-management', noCache: false },
      alwaysShow: true,
      component: SecondLayout,
      children: [{
        path: 'informationChannel',
        name: 'InformationChannel',
        component: () => import('@/views/trembleSchool/contentManagement/informationChannel/index.vue'),
        meta: { title: '资讯频道', noCache: false }
      }, {
        path: 'checkInformationChannel',
        name: 'CheckInformationChannel',
        hidden: true,
        component: () => import('@/views/trembleSchool/contentManagement/informationChannel/check.vue'),
        meta: { title: '查看资讯', noCache: false }
      }, {
        path: 'campusScenery',
        name: 'CampusScenery',
        component: () => import('@/views/trembleSchool/contentManagement/campusScenery/index'),
        meta: { title: '校园风光', noCache: false }
      }, {
        path: 'article',
        name: 'Article',
        component: () => import('@/views/trembleSchool/contentManagement/article/index'),
        meta: { title: '抖校文章', noCache: false }
      }, {
        path: 'articleDetails',
        name: 'ArticleDetails',
        hidden: true,
        component: () => import('@/views/trembleSchool/contentManagement/article/articleDetails'),
        meta: { title: '查看抖校文章', noCache: true }
      }, {
        path: 'video',
        name: 'Video',
        component: () => import('@/views/trembleSchool/contentManagement/video/index'),
        meta: { title: '抖校视频', noCache: false }
      }]
    }, {
      path: 'examine',
      name: 'TrembleSchool', // 由于是嵌套路由，它会忽略之前定义的规则，页面有多个route-view,需要多级缓存，导致第一级Name无法缓存，将children的name设置为相同即可
      meta: { title: '审核管理', icon: 'el-icon-s-check', noCache: false },
      alwaysShow: true,
      component: SecondLayout,
      children: [{
        path: 'exArticle',
        name: 'ExArticle',
        component: () => import('@/views/trembleSchool/examine/article/index'),
        meta: { title: '抖校文章审核', noCache: false }
      }, {
        path: 'exVideo',
        name: 'ExVideo',
        component: () => import('@/views/trembleSchool/examine/video/index'),
        meta: { title: '抖校视频审核', noCache: false }
      }]
    }, {
      path: 'editInformationChannel',
      name: 'EditInformationChannel',
      hidden: true,
      component: () => import('@/views/trembleSchool/contentManagement/informationChannel/edit.vue'),
      meta: { title: '修改资讯', noCache: true }
    }, {
      path: 'addInformationChannel',
      name: 'AddInformationChannel',
      hidden: true,
      component: () => import('@/views/trembleSchool/contentManagement/informationChannel/add.vue'),
      meta: { title: '新增资讯', noCache: true }
    }]
  },

  {
    path: '/systemSettings',
    component: Layout,
    redirect: '/personalInformation',
    alwaysShow: true,
    meta: { title: '系统设置', icon: 'el-icon-s-tools', roles: ['5fa50a6403755'] },
    children: [{
      path: 'personalInformation',
      name: 'PersonalInformation',
      component: () => import('@/views/systemSettings/personalInformation/index'),
      meta: { title: '个人信息', icon: 'el-icon-s-custom', noCache: false }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  base: '/permissionHtml',
  //   mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
